package cn.com.self.security.user.dto.user;

import cn.com.self.security.user.domain.LoginRoleEntity;
import cn.com.selfsoft.smartcity.commons.entity.AbstractEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.sql.Timestamp;
import java.util.List;

/**用户实体
 * @Description
 */

@TableName("t_sys_user")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SysUserEntity extends AbstractEntity {

    private static final long serialVersionUID = 1L;

    private Long id;
    /**
     * 编码
     */
    // 用户名
    private String username;
    private String openid;
    private String email;
    private String phone;
    private String idcard;
    @JsonIgnore
    private String password;

    //注册时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp registerTime;

    //注册ip
    private String registerIp;

    //最后登录时间
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Timestamp lastLoginTime;

    //最后登录ip
    private String lastLoginIp;

    //登录次数
    private Integer loginCount;

    //管理员级别
    private Integer rank;

    //是否管理员
    private Integer isAdmin;

    //是否只管理自己的数据
    private Integer isSelfAdmin;

    //是否禁用
    private Integer isDisabled;


    //所属行政编码
    private String areaCode;
    //所属行政名称
    private String areaName;
    //所属社区编码
    private String communityCode;
    //所属社区编码
    private String communityName;


    /**
     * 姓名
     */
    private String name;

    /**
     * 角色
     */
    private String roleCode;

    private Long StoreId;
    /**
     * 组织类型
     */
    private String organizationType;


    private String organizationName;
    private String governmentCode;
    private String governmentName;
    /**
     * 角色名称
     */
    private String roleName;

    /**
     * 角色
     */
    private List<LoginRoleEntity> roles;

    public static SysUserEntity user2LoginSysUser(SysUserEntity user) {
        return SysUserEntity.builder()
                .username(user.getUsername())
                .phone(user.phone)
                .password(user.getPassword())
                .roles(user.roles)
                .build();
    }
}
